/*
 * Copyright (C) 2009 TeamCity Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.cdmdotnet.android.teamcity;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost;

import com.cdmdotnet.android.teamcity.model.TCBuildProxy;
import com.cdmdotnet.android.teamcity.R;

public class BuildDetailsPage extends TabActivity {

	static final int DIALOG_STATUS = 0;

	/* (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
//        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        //setContentView(R.layout.build_detals);

        final TCBuildProxy build = new TCBuildProxy(getIntent());
        new AsyncLoader() {
			@Override
			protected void load() throws ClientProtocolException, IOException,
					JSONException {
				build.load();
			}
			@Override
			public void onLoadingFinished(int status, String errMessage) {
				// TODO Auto-generated method stub
				
			}
			@Override
			public void onLoadingStarted() {
				// TODO Auto-generated method stub
				
			}
		}.asyncLoad();
  
       final TabHost tabHost = getTabHost();

        tabHost.addTab(tabHost.newTabSpec("tab1")
                .setIndicator("Overview")
                .setContent(new Intent(getIntent()).setClass(this, BuildOverviewPage.class)));

        tabHost.addTab(tabHost.newTabSpec("tab2")
                .setIndicator("Changes (0)")
                .setContent(new Intent(getIntent()).setClass(this, BuildChangesPage.class)));
        // Set custom title
//        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.i_title_no_button);

        // This tab sets the intent flag so that it is recreated each time
        // the tab is clicked.
//        tabHost.addTab(tabHost.newTabSpec("tab3")
//                .setIndicator("destroy")
//                .setContent(new Intent(this, Controls2.class)
//                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
    }

	/* (non-Javadoc)
	 * @see android.app.Activity#onCreateDialog(int)
	 */
	@Override
	protected Dialog onCreateDialog(int id) {
		switch (id) {
		case DIALOG_STATUS:
			LayoutInflater factory = LayoutInflater.from(this);
            final View textEntryView = factory.inflate(R.layout.server_properties, null);
            return new AlertDialog.Builder(BuildDetailsPage.this)
                .setIcon(R.drawable.alert_dialog_icon)
                .setTitle("")
                .setView(textEntryView)
                .setPositiveButton(R.string.login_dialog_ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
    
                        /* User clicked OK so do some stuff */
                    }
                })
//                .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
//                    public void onClick(DialogInterface dialog, int whichButton) {
//
//                        /* User clicked cancel so do some stuff */
//                    }
//                })
                .create();
		}
		return null;
	}


}
